package com.example.demo.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

import org.apache.commons.lang3.StringUtils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;

/**
 * 商品信息
 * 
 * @author dr
 *
 */
@Entity
public class Item implements Serializable {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long iID;//

	@NotNull(message = "商品编号不能为空")
	@Column(columnDefinition = "varchar(50) COMMENT '线上系统商品编号'")
	private String itemID;// 线上系统商品编号

	@Column(columnDefinition = "varchar(50) COMMENT '商品类目编号（属于哪个类目）'")
	private String categoryID;// 商品类目编号（属于哪个类目）

	@Column(columnDefinition = "varchar(50) COMMENT 'ERP 中的店铺昵称'")
	private String shopNick;// ERP 中的店铺昵称

	@NotNull
	@Column(columnDefinition = "bigint COMMENT '仓库ID'")
	private Long sID;// 仓库ID

	@NotNull
	@Column(columnDefinition = "varchar(200) COMMENT '商品标题'")
	private String title;// 商品标题

	@Column(columnDefinition = "varchar(50) COMMENT '商家编码，商家自己输入的编码'")
	private String itemCode;// 商家编码，商家自己输入的编码

	@NotNull
	@Column(columnDefinition = "decimal(10,2) COMMENT '单价'")
	private Double price;// 单价

	@Column(columnDefinition = "int COMMENT '库存'")
	private Integer quantity;// 库存

	@Column(columnDefinition = "varchar(200) COMMENT '商品地址'")
	private String itemURL;// 商品地址

	@Column(columnDefinition = "varchar(200) COMMENT '图片地址'")
	private String imageURL;// 图片地址

	@Column(name = "i_status", columnDefinition = "int COMMENT '状态,0：已删除，1：在售，2：待售，仓库中'")
	private Integer status;// 状态,0：已删除，1：在售，2：待售，仓库中

	// @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
	@Column(columnDefinition = "timestamp COMMENT '创建时间，毫秒级时间戳，如 1421585369113'")
	private String createTime;// 创建时间，毫秒级时间戳，如 1421585369113

	// @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
	@Column(columnDefinition = "varchar(20) COMMENT '最新修改时间，毫秒级时间戳，如 1421585369113'")
	private String modifyTime;// 最新修改时间，毫秒级时间戳，如 1421585369113

	@Column(columnDefinition = "text COMMENT '商 品 属 性 ， key1:value;key2:value;... 以key:value的键值形式拼接，必须使用半角符。如生产商:万里牛;原料:实木'")
	private String properties;// 商 品 属 性 ， key1:value;key2:value;... 以key:value
								// 的键值形式拼接，必须使用半角符。如生产商:万里牛;原料:实木

	@Column(columnDefinition = "varchar(100) COMMENT '品牌，如 nike'")
	private String brand;// 品牌，如 nike

	@Column(columnDefinition = "double COMMENT '重量'")
	private Double weight;// 重量

	@Column(columnDefinition = "varchar(50) COMMENT '条码'")
	private String barcode;// 条码

	@NotNull
	@Column(columnDefinition = "text COMMENT '商品规格json串'")
	private String skuStr;// 商品规格json串

	@Transient
	private JSONArray skuJson;// 商品规格json对象

	@Column(columnDefinition = "varchar(20) COMMENT '产品上市时间'")
	private String marketTime;// 产品上市时间

	@Column(columnDefinition = "text COMMENT '说明'")
	private String itemExplain;// 说明

	public JSONArray getSkuJson() {
		if (StringUtils.isNotEmpty(this.skuStr)) {
			JSONArray array = JSON.parseArray(this.skuStr);
			skuJson = array;
		}
		return skuJson;
	}

	public Long getsID() {
		return sID;
	}

	public void setsID(Long sID) {
		this.sID = sID;
	}

	public String getItemExplain() {
		return itemExplain;
	}

	public void setItemExplain(String itemExplain) {
		this.itemExplain = itemExplain;
	}

	public void setSkuJson(JSONArray skuJson) {
		this.skuJson = skuJson;
	}

	public String getMarketTime() {
		return marketTime;
	}

	public void setMarketTime(String marketTime) {
		this.marketTime = marketTime;
	}

	public String getSkuStr() {
		return skuStr;
	}

	public void setSkuStr(String skuStr) {
		this.skuStr = skuStr;
	}

	public String getProperties() {
		return properties;
	}

	public void setProperties(String properties) {
		this.properties = properties;
	}

	public String getBrand() {
		return brand;
	}

	public void setBrand(String brand) {
		this.brand = brand;
	}

	public Double getWeight() {
		return weight;
	}

	public void setWeight(Double weight) {
		this.weight = weight;
	}

	public String getBarcode() {
		return barcode;
	}

	public void setBarcode(String barcode) {
		this.barcode = barcode;
	}

	public Long getiID() {
		return iID;
	}

	public void setiID(Long iID) {
		this.iID = iID;
	}

	public String getItemID() {
		return itemID;
	}

	public void setItemID(String itemID) {
		this.itemID = itemID;
	}

	public String getCategoryID() {
		return categoryID;
	}

	public void setCategoryID(String categoryID) {
		this.categoryID = categoryID;
	}

	public String getShopNick() {
		return shopNick;
	}

	public void setShopNick(String shopNick) {
		this.shopNick = shopNick;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getItemCode() {
		return itemCode;
	}

	public void setItemCode(String itemCode) {
		this.itemCode = itemCode;
	}

	public Double getPrice() {
		return price;
	}

	public void setPrice(Double price) {
		this.price = price;
	}

	public Integer getQuantity() {
		return quantity;
	}

	public void setQuantity(Integer quantity) {
		this.quantity = quantity;
	}

	public String getItemURL() {
		return itemURL;
	}

	public void setItemURL(String itemURL) {
		this.itemURL = itemURL;
	}

	public String getImageURL() {
		return imageURL;
	}

	public void setImageURL(String imageURL) {
		this.imageURL = imageURL;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public String getCreateTime() {
		return createTime;
	}

	public void setCreateTime(String createTime) {
		this.createTime = createTime;
	}

	public String getModifyTime() {
		return modifyTime;
	}

	public void setModifyTime(String modifyTime) {
		this.modifyTime = modifyTime;
	}

	private static final long serialVersionUID = -8601290514642529913L;

}
